package com.vincent.service;

import com.vincent.common.enums.ResultMapKey;
import com.vincent.dao.ShiroDao;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

/**
 * Created by Vincent on 2014/12/23.
 */
@Service("realmService")
public class RealmService {
    @Resource
    private ShiroDao shiroDao;

    /**
     * 获取管理员授权信息
     *
     * @param userId
     * @return
     */
    public Map<String, Object> findAdminAuthorizationInfo(int userId) {
        Map<String, Object> resultmap = new HashMap<String, Object>();

        List<String> perNameList = shiroDao.selectPerNamesByAdminId(userId);

        SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
        authorizationInfo.setStringPermissions(new HashSet<String>(perNameList));
        resultmap.put(ResultMapKey.SUCCESS.getCode(), authorizationInfo);
        return resultmap;
    }
}
